package cn.bone.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
public class PaymentController {

    @Value("${server.port}")
    private String serverPort;

    @RequestMapping("/payment/consul2")
    public String paymentConsul(){

        log.info("/payment/consul2 in port:{}",serverPort);
        String result = "springcloud with consul-2: "
                + serverPort
                +"\t"
                + UUID.randomUUID().toString();
        return result;
    }

    @RequestMapping("/payment/timeOut")
    public String paymentTimeOut(){

        log.info("/payment/timeOut in port:{}",serverPort);
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        String result = "springcloud payment timeOut with consul-2: "
                + serverPort
                +"\t"
                + UUID.randomUUID().toString();
        return result;
    }

    @RequestMapping("/payment/zipkin")
    public String paymentZipkin(){
        log.info("/payment/zipkin in port:{}",serverPort);

        String result = "springcloud payment zipkin with consul-2: "
                + serverPort
                +"\t"
                + UUID.randomUUID().toString();
        return result;
    }
}
